<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2017/1/15
 * Time: 下午5:36
 */
class OnlineController extends AdminBaseController {

    public function warning(){
        $this->setTitle('在线报警列表');

        $filter = new PubFilter();
        $grid   = new PubGrid();

        $statusOptions = WarningService::onlineStatus();

        $filter->addFilter('status', 'radio', '状态', array('options' => $statusOptions, 'value' => 1));

        $params = $filter->get();

        $header = WarningService::onlineHeader();
        $data   = WarningService::onlineData($params);
        $grid->addGrid($header, $data, array(
            'order' => array('create_time', 'desc'),
        ));

        $this->out['online'] = WarningService::getOnlineInfo();

        $this->out['filter'] = $filter->show();
        $this->out['grid'] = $grid->show();
    }

    public function setting(){
        $this->setTitle('在线报警配置');
        $this->out['online'] = WarningService::getOnlineInfo();
    }

    public function saveSetting(){
        $params = array(
            'mail'      => $this->R('mail_list'),
            'threshold' => $this->R('threshold'),
        );

        WarningService::saveSetting($params);

        $url = PubFunc::buildUrl('/oss/?r=online/setting');
        $this->showMessage('保存成功', $url);
    }

}